home *** CD-ROM | disk | FTP | other *** search
/ 3D Game Programming All in One / 3D Game Programming All in One Disc.iso / 3D2E / RESOURCES / CH20 / car.cs < prev    next >
Text File  |  2006-09-23  |  4KB  |  129 lines

  1. //-----------------------------------------------------------------------------
  2. // Torque Game Engine
  3. // Copyright (C) GarageGames.com, Inc.
  4. //-----------------------------------------------------------------------------
  5.  
  6. //-----------------------------------------------------------------------------
  7.  
  8. // Information extacted from the shape.
  9. //
  10. // Wheel Sequences
  11. //    spring#        Wheel spring motion: time 0 = wheel fully extended,
  12. //                   the hub must be displaced, but not directly animated
  13. //                   as it will be rotated in code.
  14. // Other Sequences
  15. //    steering       Wheel steering: time 0 = full right, 0.5 = center
  16. //    breakLight     Break light, time 0 = off, 1 = breaking
  17. //
  18. // Wheel Nodes
  19. //    hub#           Wheel hub, the hub must be in it's upper position
  20. //                   from which the springs are mounted.
  21. //
  22. // The steering and animation sequences are optional.
  23. // The center of the shape acts as the center of mass for the car.
  24.  
  25. //-----------------------------------------------------------------------------
  26.  
  27. datablock ParticleData(TireParticle)
  28. {
  29.    textureName          = "~/data/particles/dustParticle";
  30.    dragCoefficient      = 2.0;
  31.    gravityCoefficient   = -0.1;
  32.    inheritedVelFactor   = 0.1;
  33.    constantAcceleration = 0.0;
  34.    lifetimeMS           = 1000;
  35.    lifetimeVarianceMS   = 0;
  36.    colors[0]     = "0.46 0.36 0.26 1.0";
  37.    colors[1]     = "0.46 0.46 0.36 0.0";
  38.    sizes[0]      = 0.50;
  39.    sizes[1]      = 1.0;
  40. };
  41.  
  42. datablock ParticleEmitterData(TireEmitter)
  43. {
  44.    ejectionPeriodMS = 10;
  45.    periodVarianceMS = 0;
  46.    ejectionVelocity = 1;
  47.    velocityVariance = 1.0;
  48.    ejectionOffset   = 0.0;
  49.    thetaMin         = 5;
  50.    thetaMax         = 20;
  51.    phiReferenceVel  = 0;
  52.    phiVariance      = 360;
  53.    overrideAdvance = false;
  54.    particles = "TireParticle";
  55. };
  56.  
  57.  
  58. //----------------------------------------------------------------------------
  59.  
  60. datablock WheeledVehicleTire(DefaultCarTire)
  61. {
  62.    // Tires act as springs and generate lateral and longitudinal
  63.    // forces to move the vehicle. These distortion/spring forces
  64.    // are what convert wheel angular velocity into forces that
  65.    // act on the rigid body.
  66.    shapeFile = "~/data/models/vehicles/wheel.dts";
  67.    staticFriction = 4;
  68.    kineticFriction = 1.25;
  69.  
  70.    // Spring that generates lateral tire forces
  71.    lateralForce = 18000;
  72.    lateralDamping = 4000;
  73.    lateralRelaxation = 1;
  74.  
  75.    // Spring that generates longitudinal tire forces
  76.    longitudinalForce = 18000;
  77.    longitudinalDamping = 4000;
  78.    longitudinalRelaxation = 1;
  79. };
  80.  
  81. datablock WheeledVehicleSpring(DefaultCarSpring)
  82. {
  83.    // Wheel suspension properties
  84.    length = 0.85;             // Suspension travel
  85.    force = 3000;              // Spring force
  86.    damping = 600;             // Spring damping
  87.    antiSwayForce = 3;         // Lateral anti-sway force
  88. };
  89.  
  90.  
  91.  
  92.  
  93.  
  94. //-----------------------------------------------------------------------------
  95.  
  96. function WheeledVehicleData::create(%block)
  97. {
  98.    %obj = new WheeledVehicle() {
  99.       dataBlock = %block;
  100.       mountable = true;
  101.    };
  102.    return(%obj);
  103. }
  104.  
  105. //-----------------------------------------------------------------------------
  106.  
  107. function WheeledVehicleData::onAdd(%this,%obj)
  108. {
  109.    // Setup the car with some defaults tires & springs
  110.    for (%i = %obj.getWheelCount() - 1; %i >= 0; %i--) {
  111.       %obj.setWheelTire(%i,DefaultCarTire);
  112.       %obj.setWheelSpring(%i,DefaultCarSpring);
  113.       %obj.setWheelPowered(%i,false);
  114.    }
  115.  
  116.    // Steer front tires
  117.    %obj.setWheelSteering(0,1);
  118.    %obj.setWheelSteering(1,1);
  119.  
  120.    // Only power the two rear wheels...
  121.    %obj.setWheelPowered(2,true);
  122.    %obj.setWheelPowered(3,true);
  123. }
  124.  
  125. function WheeledVehicleData::onCollision(%this,%obj,%col,%vec,%speed)
  126. {
  127.    // Collision with other objects, including items
  128. }
  129.